package BanyuanClub.Work.项目;

public class lajizhan {
    /**
     * //保存输入的内容
     *     private int in = 0;
     *     ConcurrentHashMap<String, String> content = new ConcurrentHashMap<>();
     *
     *     //通讯
     *     public void cilderPortMethod(){
     *         new Thread(()-> {
     *             try {
     *                 Socket socket = new Socket(IP, portNumner);
     *                 if (portNumner == charkServer.getPortNumber()) {
     *                     textArea.append("登录成功\n");
     *                 }
     *                 PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
     *                 BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     *                 new Thread(() -> {
     *                         //发送消息
     *                     if (content.get(in + "") != null){
     *                         String s = content.get(in + "");
     *                         pw.println(s);
     *                     }
     *                 }).start();
     *
     *                 while (true) {
     *                     String s = br.readLine();
     *                     textArea.append(s);
     *                 }
     *             } catch (IOException e) {
     *                 e.printStackTrace();
     *             }
     *         }).start();
     *     }
     *
     *
     *     //通讯方法
     *     public void serverPortMethod(){
     *         new Thread(() ->{
     *             try {
     *                 ServerSocket server = new ServerSocket(portNumber);
     *                 //负责群发
     *                 new Thread(()->{
     *                     if (content.get(in + "") != null) {
     *                         for (PrintWriter out : pwarr.values()
     *                         ) {
     *                             out.println(content.get(in +""));
     *                         }
     *                     }
     *                 }).start();
     *                 while (true) {
     *                     Socket socket = server.accept();
     *                     textArea.append("已链接\n");
     *                     PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
     *                     BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     *                     pwarr.put(index++ + "", pw);
     *                     new Thread(() -> {
     *                         while (true) {
     *                             try {
     *                                 for (PrintWriter pw1:pwarr.values()
     *                                 ) {
     *                                     pw1.println(br.readLine());
     *                                 }
     *                                 textArea.append(br.readLine());
     *                             } catch (IOException e) {
     *                                 e.printStackTrace();
     *                             }
     *                         }
     *                     }).start();
     *                 }
     *             } catch (IOException e) {
     *                 e.printStackTrace();
     *             }
     *         }).start();
     *     }
     *
     * 客户端保存 index 为链接人数，即在线人数
     *     private int index = 1;
     *
     *     public int getIndex() {
     *         return index;
     *     }
     *
     *     ConcurrentHashMap<String, PrintWriter> pwarr = new ConcurrentHashMap<>();
     *     private int in = 0;
     *     ConcurrentHashMap<String, String> content = new ConcurrentHashMap<>();
     *
     *
     *     //链接服务器
     *     Socket socket;
     *     public void serverLink(){
     *         new Thread(()-> {
     *             textArea.append("正在登录\n");
     *             if (IP == null){
     *                 textArea.append("IP未设置\n");
     *             }
     *             if(portNumner != charkServer.getPortNumber()){
     *                 textArea.append("端口号不正确\n");
     *             }
     *             try {
     *                 socket = new Socket(IP, portNumner);
     *                 textArea.append("登录成功\n");
     *                 writer = new PrintWriter(socket.getOutputStream(),true);
     *                 reader = new BufferedReader(
     *                         new InputStreamReader(socket.getInputStream()));
     *                 while (true) {
     *                     new Thread(() ->{
     *                         writer.println(sarr.get(anInt - 1 + ""));
     *                     }).start();
     *                     String s;
     *                     while ((s = reader.readLine()) != null) {
     *                         textArea.append(s);
     *                     }
     *                     textArea.append("可以走到这里");
     *                 }
     *             } catch (IOException e) {
     *                 e.printStackTrace();
     *             }
     *         }).start();
     *     }
     *
     *
     * //链接客户
     *     public void clientLink(){
     *         new Thread(()-> {
     *             try {
     *                 if (portNumber == 0){
     *                     textArea.append("端口号未设置");
     *                 }
     *                 server = new ServerSocket(portNumber);
     *                 textArea.append("服务端已启动\n");
     *                 while (true) {
     *                     Socket socket = server.accept();
     *                     textArea.append("服务端已链接\n");
     *                     writer = new PrintWriter(socket.getOutputStream(),true);
     *                         pwarr.put(index+++"",writer);
     *                     new Thread(()->{
     *                         String st = sarr.get(anInt - 1 + "");
     *                         if (st != null) {
     *                             writer.println(st);
     *                         }
     *                     }).start();
     *                     Thread dispose = new Thread(new Dispose(socket));
     *                     dispose.start();
     *                 }
     *             } catch (IOException e) {
     *                 e.printStackTrace();
     *             }
     *         }).start();
     *     }
     *
     *     //接收客户请求内部类
     8  class Dispose implements Runnable{
     *         Socket socket;
     *         private BufferedReader br;
     *         private String message;
     *
     *         public Dispose(Socket socket) {
     *             this.socket = socket;
     *         }
     *
     *         @Override
     *         public void run() {
     *             try {
     *                 br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     *                 while ((message = br.readLine()) != null){
     *                     sendMessage(message);
     *                 }
     *             } catch (IOException e) {
     *                 e.printStackTrace();
     *             }
     *         }
     *     }
     *
     *     //群发消息方法
     *     public void sendMessage(String message){
     *         textArea.append(message);
     *         for (PrintWriter out:pwarr.values()
     *              ) {
     *             out.println(message);
     *             out.flush();
     *         }
     *     }
     *
     *
     * new Thread(() ->{
     *                         writer.println(sarr.get(anInt - 1 + ""));
     *                     }).start();
     *
     *  //负责群发
     *             new Thread(() -> {
     *                 while (true) {
     *                     String st = textField.getText();
     *                     try {
     *                         for (BufferedWriter out : bwarr.values()
     *                         ) {
     *                             out.write("服务器：" + st);
     *                         }
     *                     } catch (IOException e) {
     *                         e.printStackTrace();
     *                     }
     *                 }
     *             }).start();
     */
}
